package response

import (
	"longmen/server/internal/services/nami/services/esport/dota2"
	"longmen/server/pkg/db/mysql/models/models_esports"
)

type (
	TournamentApiResponse struct {
		Code  int `json:"code"`
		Query struct {
			Limit int    `json:"limit"`
			Type  string `json:"type"`
			Total int    `json:"total"`
			ID    int    `json:"id"`
			MinID int    `json:"min_id"`
			MaxID int    `json:"max_id"`
		} `json:"query"`
		Results []Tournament `json:"results"`
	}

	Tournament struct {
		ID         int    `json:"id"`
		NameZh     string `json:"name_zh"`
		NameEn     string `json:"name_en"`
		AbbrEn     string `json:"abbr_en"`
		AbbrZh     string `json:"abbr_zh"`
		StatusID   int    `json:"status_id"`
		Logo       string `json:"logo"`
		Cover      string `json:"cover"`
		StartTime  int    `json:"start_time"`
		EndTime    int    `json:"end_time"`
		CityName   string `json:"city_name"`
		CityNameEn string `json:"city_name_en"`
		Type       int    `json:"type"`
		PricePool  string `json:"price_pool"`
		UpdatedAt  int    `json:"updated_at"`
	}
)

func (t Tournament) Get() models_esports.Dota2Tournament {
	return models_esports.Dota2Tournament{
		ID:         t.ID,
		NameEn:     t.NameEn,
		NameZh:     t.NameZh,
		AbbrEn:     t.AbbrEn,
		AbbrZh:     t.AbbrZh,
		StatusID:   t.StatusID,
		Logo:       t.Logo,
		Cover:      t.Cover,
		StartTime:  t.StartTime,
		EndTime:    t.EndTime,
		Type:       t.Type,
		UpdatedAt:  t.UpdatedAt,
		PricePool:  t.PricePool,
		CityName:   t.CityName,
		CityNameEn: t.CityNameEn,
	}
}

func (t TournamentApiResponse) Interfaces() []dota2.InsertTournamentInterface {
	records := make([]dota2.InsertTournamentInterface, 0)
	for _, result := range t.Results {
		records = append(records, result)
	}
	return records
}
